#include "floor2.h"
#include "ui_floor2.h"

floor2::floor2(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::floor2)
{
    ui->setupUi(this);
    this->setGeometry(QRect(435,100,700,700));
}

floor2::~floor2()
{
    delete ui;
}
void floor2::paintEvent(QPaintEvent*event)//update()或程序第一次启动时自动执行，用于画图
{
    QPainter painter(this);
    painter.setPen(Qt::black);
    painter.setBrush(Qt::black);
    painter.drawRect(15,15,20,570);//1
    painter.drawRect(15,15,520,20);//2
    painter.drawRect(280,15,20,140);//3
    painter.drawRect(15,390,135,20);//13
    painter.drawRect(480,320,105,20);//8
    painter.drawRect(330,390,20,181);//10
    painter.drawRect(310,210,20,80);//11
    painter.drawRect(310,270,70,20);//12
    painter.drawRect(515,15,20,100);//5
    painter.drawRect(515,95,70,20);//6
    painter.drawRect(565,95,20,490);//7
    painter.drawRect(15,565,570,20);//9
    painter.drawRect(150,260,20,150);//4

   // painter.drawRect()
}
void floor2::moveadventurer(QRect &adventurer1,int direction1,int speed)
{
      bool dopeng=false;
        if(adventurer1.right()>150&&adventurer1.left()<170)//4
        {
           if((adventurer1.top()<410&&adventurer1.bottom()>260)&&(adventurer1.left()>150||adventurer1.right()<170))
            {
                dopeng=true;
            }
        }
        if(adventurer1.top()<410&&adventurer1.bottom()>390)//13
        {
            if(adventurer1.left()<170&&(adventurer1.top()>390||adventurer1.bottom()<410))
            {
                dopeng=true;
            }
        }
        if(adventurer1.left()<300&&adventurer1.right()>280)//3
        {
          if(adventurer1.top()<155&&(adventurer1.left()>280||adventurer1.right()<300))
            {
                dopeng=true;
            }
        }
        if(adventurer1.right()>310&&adventurer1.left()<330)//11
        {
            if((adventurer1.top()<290&&adventurer1.bottom()>210)&&(adventurer1.left()>310||adventurer1.right()<330))
            {
                dopeng=true;
            }
        }
        if(adventurer1.right()>310&&adventurer1.left()<380)//12
        {
            if((adventurer1.top()<290&&adventurer1.bottom()>270)&&(adventurer1.left()>310||adventurer1.right()<380))
            {
                dopeng=true;
            }
        }
        if(adventurer1.right()>330&&adventurer1.left()<350)//10
        {
            if((adventurer1.bottom()>390)&&(adventurer1.left()>330||adventurer1.right()<350))
            {
                dopeng=true;
            }
        }

    if(adventurer1.right()>480)//8
    {
        if(adventurer1.top()<340&&adventurer1.bottom()>320)
        {
            dopeng=true;
        }
    }
    if(adventurer1.left()<35||adventurer1.right()>565||adventurer1.bottom()>565||adventurer1.top()<35)// 1 2 7 9
    {
        dopeng=true;
    }
    if(adventurer1.right()>515&&adventurer1.top()<115)
    {
        dopeng=true;
    }
    if(dopeng==true)
    {
    if(direction1==1)
    {
        adventurer1.moveTo(adventurer1.left(),adventurer1.top()+speed);
    }
    else if(direction1==2)
    {
        adventurer1.moveTo(adventurer1.left(),adventurer1.top()-speed);
    }
    else if(direction1==3)
    {
        adventurer1.moveTo(adventurer1.left()+speed,adventurer1.top());
    }
    else if(direction1==4)
    {
        adventurer1.moveTo(adventurer1.left()-speed,adventurer1.top());
    }
    }
}
























